home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / motion.zip / WEAPONS.QC < prev   
Text File  |  1996-08-11  |  26KB  |  1,228 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav"); // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");  // super spikes
  21.     precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");      // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  25.  
  26.     precache_model ("progs/v_spike.mdl");
  27. };
  28.  
  29. float() crandom =
  30. {
  31.     return 2*(random() - 0.5);
  32. };
  33.  
  34. /*
  35. ================
  36. W_FireAxe
  37. ================
  38. */
  39. void() W_FireAxe =
  40. {
  41.     local   vector  source;
  42.     local   vector  org;
  43.  
  44.     source = self.origin + '0 0 16';
  45.     traceline (source, source + v_forward*64, FALSE, self);
  46.     if (trace_fraction == 1.0)
  47.         return;
  48.     
  49.     org = trace_endpos - v_forward*4;
  50.  
  51.     if (trace_ent.takedamage)
  52.     {
  53.         trace_ent.axhitme = 1;
  54.         SpawnBlood (org, '0 0 0', 20);
  55.         T_Damage (trace_ent, self, self, 20);
  56.     }
  57.     else
  58.     {   // hit wall
  59.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  60.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  61.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  62.         WriteCoord (MSG_BROADCAST, org_x);
  63.         WriteCoord (MSG_BROADCAST, org_y);
  64.         WriteCoord (MSG_BROADCAST, org_z);
  65.     }
  66. };
  67.  
  68.  
  69. //============================================================================
  70.  
  71.  
  72. vector() wall_velocity =
  73. {
  74.     local vector    vel;
  75.     
  76.     vel = normalize (self.velocity);
  77.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  78.     vel = vel + 2*trace_plane_normal;
  79.     vel = vel * 200;
  80.     
  81.     return vel;
  82. };
  83.  
  84.  
  85. /*
  86. ================
  87. SpawnMeatSpray
  88. ================
  89. */
  90. void(vector org, vector vel) SpawnMeatSpray =
  91. {
  92.     local   entity missile, mpuff;
  93.     local   vector  org;
  94.  
  95.     missile = spawn ();
  96.     missile.owner = self;
  97.     missile.movetype = MOVETYPE_BOUNCE;
  98.     missile.solid = SOLID_NOT;
  99.  
  100.     makevectors (self.angles);
  101.  
  102.     missile.velocity = vel;
  103.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  104.  
  105.     missile.avelocity = '3000 1000 2000';
  106.     
  107. // set missile duration
  108.     missile.nextthink = time + 1;
  109.     missile.think = SUB_Remove;
  110.  
  111.     setmodel (missile, "progs/zom_gib.mdl");
  112.     setsize (missile, '0 0 0', '0 0 0');        
  113.     setorigin (missile, org);
  114. };
  115.  
  116. /*
  117. ================
  118. SpawnBlood
  119. ================
  120. */
  121. void(vector org, vector vel, float damage) SpawnBlood =
  122. {
  123.     particle (org, vel*0.1, 73, damage*2);
  124. };
  125.  
  126. /*
  127. ================
  128. spawn_touchblood
  129. ================
  130. */
  131. void(float damage) spawn_touchblood =
  132. {
  133.     local vector    vel;
  134.  
  135.     vel = wall_velocity () * 0.2;
  136.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  137. };
  138.  
  139.  
  140. /*
  141. ================
  142. SpawnChunk
  143. ================
  144. */
  145. void(vector org, vector vel) SpawnChunk =
  146. {
  147.     particle (org, vel*0.02, 0, 10);
  148. };
  149.  
  150. /*
  151. ==============================================================================
  152.  
  153. MULTI-DAMAGE
  154.  
  155. Collects multiple small damages into a single damage
  156.  
  157. ==============================================================================
  158. */
  159.  
  160. entity  multi_ent;
  161. float   multi_damage;
  162.  
  163. void() ClearMultiDamage =
  164. {
  165.     multi_ent = world;
  166.     multi_damage = 0;
  167. };
  168.  
  169. void() ApplyMultiDamage =
  170. {
  171.     if (!multi_ent)
  172.         return;
  173.     T_Damage (multi_ent, self, self, multi_damage);
  174. };
  175.  
  176. void(entity hit, float damage) AddMultiDamage =
  177. {
  178.     if (!hit)
  179.         return;
  180.     
  181.     if (hit != multi_ent)
  182.     {
  183.         ApplyMultiDamage ();
  184.         multi_damage = damage;
  185.         multi_ent = hit;
  186.     }
  187.     else
  188.         multi_damage = multi_damage + damage;
  189. };
  190.  
  191. /*
  192. ==============================================================================
  193.  
  194. BULLETS
  195.  
  196. ==============================================================================
  197. */
  198.  
  199. /*
  200. ================
  201. TraceAttack
  202. ================
  203. */
  204. void(float damage, vector dir) TraceAttack =
  205. {
  206.     local   vector  vel, org;
  207.     
  208.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  209.     vel = vel + 2*trace_plane_normal;
  210.     vel = vel * 200;
  211.  
  212.     org = trace_endpos - dir*4;
  213.  
  214.     if (trace_ent.takedamage)
  215.     {
  216.         SpawnBlood (org, vel*0.2, damage);
  217.         AddMultiDamage (trace_ent, damage);
  218.     }
  219.     else
  220.     {
  221.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  222.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  223.         WriteCoord (MSG_BROADCAST, org_x);
  224.         WriteCoord (MSG_BROADCAST, org_y);
  225.         WriteCoord (MSG_BROADCAST, org_z);
  226.     }
  227. };
  228.  
  229. /*
  230. ================
  231. FireBullets
  232.  
  233. Used by shotgun, super shotgun, and enemy soldier firing
  234. Go to the trouble of combining multiple pellets into a single damage call.
  235. ================
  236. */
  237. void(float shotcount, vector dir, vector spread) FireBullets =
  238. {
  239.     local   vector direction;
  240.     local   vector  src;
  241.     
  242.     makevectors(self.v_angle);
  243.  
  244.     src = self.origin + v_forward*10;
  245.     src_z = self.absmin_z + self.size_z * 0.7;
  246.  
  247.     ClearMultiDamage ();
  248.     while (shotcount > 0)
  249.     {
  250.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  251.  
  252.         traceline (src, src + direction*2048, FALSE, self);
  253.         if (trace_fraction != 1.0)
  254.             TraceAttack (4, direction);
  255.  
  256.         shotcount = shotcount - 1;
  257.     }
  258.     ApplyMultiDamage ();
  259. };
  260.  
  261. /*
  262. ================
  263. W_FireShotgun
  264. ================
  265. */
  266. void() W_FireShotgun =
  267. {
  268.     local vector dir;
  269.  
  270.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  271.  
  272.     self.punchangle_x = -2;
  273.     
  274.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  275.     dir = aim (self, 100000);
  276.     FireBullets (6, dir, '0.04 0.04 0');
  277. };
  278.  
  279.  
  280. /*
  281. ================
  282. W_FireSuperShotgun
  283. ================
  284. */
  285. void() W_FireSuperShotgun =
  286. {
  287.     local vector dir;
  288.  
  289.     if (self.currentammo == 1)
  290.     {
  291.         W_FireShotgun ();
  292.         return;
  293.     }
  294.         
  295.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  296.  
  297.     self.punchangle_x = -4;
  298.     
  299.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  300.     dir = aim (self, 100000);
  301.     FireBullets (14, dir, '0.14 0.08 0');
  302. };
  303.  
  304.  
  305. /*
  306. ==============================================================================
  307.  
  308. ROCKETS
  309.  
  310. ==============================================================================
  311. */
  312.  
  313. void()  s_explode1  =   [0,     s_explode2] {};
  314. void()  s_explode2  =   [1,     s_explode3] {};
  315. void()  s_explode3  =   [2,     s_explode4] {};
  316. void()  s_explode4  =   [3,     s_explode5] {};
  317. void()  s_explode5  =   [4,     s_explode6] {};
  318. void()  s_explode6  =   [5,     SUB_Remove] {};
  319.  
  320. void() BecomeExplosion =
  321. {
  322.     self.movetype = MOVETYPE_NONE;
  323.     self.velocity = '0 0 0';
  324.     self.touch = SUB_Null;
  325.     setmodel (self, "progs/s_explod.spr");
  326.     self.solid = SOLID_NOT;
  327.     s_explode1 ();
  328. };
  329.  
  330. void() T_MissileTouch =
  331. {
  332.     local float damg;
  333.  
  334.     if (other == self.owner)
  335.         return;     // don't explode on owner
  336.  
  337.     if (pointcontents(self.origin) == CONTENT_SKY)
  338.     {
  339.         remove(self);
  340.         return;
  341.     }
  342.  
  343.     damg = 100 + random()*20;
  344.     
  345.     if (other.health)
  346.     {
  347.         if (other.classname == "monster_shambler")
  348.             damg = damg * 0.5;  // mostly immune
  349.         T_Damage (other, self, self.owner, damg );
  350.     }
  351.  
  352.     // don't do radius damage to the other, because all the damage
  353.     // was done in the impact
  354.     T_RadiusDamage (self, self.owner, 120, other);
  355.  
  356. //  sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  357.     self.origin = self.origin - 8*normalize(self.velocity);
  358.  
  359.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  360.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  361.     WriteCoord (MSG_BROADCAST, self.origin_x);
  362.     WriteCoord (MSG_BROADCAST, self.origin_y);
  363.     WriteCoord (MSG_BROADCAST, self.origin_z);
  364.  
  365.     BecomeExplosion ();
  366. };
  367.  
  368.  
  369.  
  370. /*
  371. ================
  372. W_FireRocket
  373. ================
  374. */
  375. void() W_FireRocket =
  376. {
  377.     local   entity missile, mpuff;
  378.     
  379.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  380.     
  381.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  382.  
  383.     self.punchangle_x = -2;
  384.  
  385.     missile = spawn ();
  386.     missile.owner = self;
  387.     missile.movetype = MOVETYPE_FLYMISSILE;
  388.     missile.solid = SOLID_BBOX;
  389.         
  390. // set missile speed    
  391.  
  392.     makevectors (self.v_angle);
  393.     missile.velocity = aim(self, 1000);
  394.     missile.velocity = missile.velocity * 1000;
  395.     missile.angles = vectoangles(missile.velocity);
  396.     
  397.     missile.touch = T_MissileTouch;
  398.     
  399. // set missile duration
  400.     missile.nextthink = time + 5;
  401.     missile.think = SUB_Remove;
  402.  
  403.     setmodel (missile, "progs/missile.mdl");
  404.     setsize (missile, '0 0 0', '0 0 0');        
  405.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  406. };
  407.  
  408. /*
  409. ===============================================================================
  410.  
  411. LIGHTNING
  412.  
  413. ===============================================================================
  414. */
  415.  
  416. /*
  417. =================
  418. LightningDamage
  419. =================
  420. */
  421. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  422. {
  423.     local entity        e1, e2;
  424.     local vector        f;
  425.     
  426.     f = p2 - p1;
  427.     normalize (f);
  428.     f_x = 0 - f_y;
  429.     f_y = f_x;
  430.     f_z = 0;
  431.     f = f*16;
  432.  
  433.     e1 = e2 = world;
  434.  
  435.     traceline (p1, p2, FALSE, self);
  436.     if (trace_ent.takedamage)
  437.     {
  438.         particle (trace_endpos, '0 0 100', 225, damage*4);
  439.         T_Damage (trace_ent, from, from, damage);
  440.         if (self.classname == "player")
  441.         {
  442.             if (other.classname == "player")
  443.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  444.         }
  445.     }
  446.     e1 = trace_ent;
  447.  
  448.     traceline (p1 + f, p2 + f, FALSE, self);
  449.     if (trace_ent != e1 && trace_ent.takedamage)
  450.     {
  451.         particle (trace_endpos, '0 0 100', 225, damage*4);
  452.         T_Damage (trace_ent, from, from, damage);
  453.     }
  454.     e2 = trace_ent;
  455.  
  456.     traceline (p1 - f, p2 - f, FALSE, self);
  457.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  458.     {
  459.         particle (trace_endpos, '0 0 100', 225, damage*4);
  460.         T_Damage (trace_ent, from, from, damage);
  461.     }
  462. };
  463.  
  464.  
  465. void() W_FireLightning =
  466. {
  467.     local   vector      org;
  468.  
  469.     if (self.ammo_cells < 1)
  470.     {
  471.         self.weapon = W_BestWeapon ();
  472.         W_SetCurrentAmmo ();
  473.         return;
  474.     }
  475.  
  476. // explode if under water
  477.     if (self.waterlevel > 1)
  478.     {
  479.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  480.         self.ammo_cells = 0;
  481.         W_SetCurrentAmmo ();
  482.         return;
  483.     }
  484.  
  485.     if (self.t_width < time)
  486.     {
  487.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  488.         self.t_width = time + 0.6;
  489.     }
  490.     self.punchangle_x = -2;
  491.  
  492.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  493.  
  494.     org = self.origin + '0 0 16';
  495.     
  496.     traceline (org, org + v_forward*600, TRUE, self);
  497.  
  498.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  499.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  500.     WriteEntity (MSG_BROADCAST, self);
  501.     WriteCoord (MSG_BROADCAST, org_x);
  502.     WriteCoord (MSG_BROADCAST, org_y);
  503.     WriteCoord (MSG_BROADCAST, org_z);
  504.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  505.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  506.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  507.  
  508.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  509. };
  510.  
  511.  
  512. //=============================================================================
  513.  
  514.  
  515. void() GrenadeExplode =
  516. {
  517.     T_RadiusDamage (self, self.owner, 120, world);
  518.  
  519.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  520.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  521.     WriteCoord (MSG_BROADCAST, self.origin_x);
  522.     WriteCoord (MSG_BROADCAST, self.origin_y);
  523.     WriteCoord (MSG_BROADCAST, self.origin_z);
  524.  
  525.     BecomeExplosion ();
  526. };
  527.  
  528. void() GrenadeTouch =
  529. {
  530.     if (other == self.owner)
  531.         return;     // don't explode on owner
  532.     if (other.takedamage == DAMAGE_AIM)
  533.     {
  534.         GrenadeExplode();
  535.         return;
  536.     }
  537.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  538.     if (self.velocity == '0 0 0')
  539.         self.avelocity = '0 0 0';
  540. };
  541.  
  542. /*
  543. ================
  544. W_FireGrenade
  545. ================
  546. */
  547. void() W_FireGrenade =
  548. {
  549.     local   entity missile, mpuff;
  550.     
  551.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  552.     
  553.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  554.  
  555.     self.punchangle_x = -2;
  556.  
  557.     missile = spawn ();
  558.     missile.owner = self;
  559.     missile.movetype = MOVETYPE_BOUNCE;
  560.     missile.solid = SOLID_BBOX;
  561.     missile.classname = "grenade";
  562.         
  563. // set missile speed    
  564.  
  565.     makevectors (self.v_angle);
  566.  
  567.     if (self.v_angle_x)
  568.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  569.     else
  570.     {
  571.         missile.velocity = aim(self, 10000);
  572.         missile.velocity = missile.velocity * 600;
  573.         missile.velocity_z = 200;
  574.     }
  575.  
  576.     missile.avelocity = '300 300 300';
  577.  
  578.     missile.angles = vectoangles(missile.velocity);
  579.     
  580.     missile.touch = GrenadeTouch;
  581.     
  582. // set missile duration
  583.     missile.nextthink = time + 2.5;
  584.     missile.think = GrenadeExplode;
  585.  
  586.     setmodel (missile, "progs/grenade.mdl");
  587.     setsize (missile, '0 0 0', '0 0 0');        
  588.     setorigin (missile, self.origin);
  589. };
  590.  
  591.  
  592. //=============================================================================
  593.  
  594. void() spike_touch;
  595. void() superspike_touch;
  596.  
  597.  
  598. /*
  599. ===============
  600. launch_spike
  601.  
  602. Used for both the player and the ogre
  603. ===============
  604. */
  605. void(vector org, vector dir) launch_spike =
  606. {
  607.     newmis = spawn ();
  608.     newmis.owner = self;
  609.     newmis.movetype = MOVETYPE_FLYMISSILE;
  610.     newmis.solid = SOLID_BBOX;
  611.  
  612.     newmis.angles = vectoangles(dir);
  613.     
  614.     newmis.touch = spike_touch;
  615.     newmis.classname = "spike";
  616.     newmis.think = SUB_Remove;
  617.     newmis.nextthink = time + 6;
  618.     setmodel (newmis, "progs/spike.mdl");
  619.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);       
  620.     setorigin (newmis, org);
  621.  
  622.     newmis.velocity = dir * 1000;
  623. };
  624.  
  625. void() W_FireSuperSpikes =
  626. {
  627.     local vector    dir;
  628.     local entity    old;
  629.     
  630.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  631.     self.attack_finished = time + 0.2;
  632.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  633.     dir = aim (self, 1000);
  634.     launch_spike (self.origin + '0 0 16', dir);
  635.     newmis.touch = superspike_touch;
  636.     setmodel (newmis, "progs/s_spike.mdl");
  637.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);       
  638.     self.punchangle_x = -2;
  639. };
  640.  
  641. void(float ox) W_FireSpikes =
  642. {
  643.     local vector    dir;
  644.     local entity    old;
  645.     
  646.     makevectors (self.v_angle);
  647.     
  648.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  649.     {
  650.         W_FireSuperSpikes ();
  651.         return;
  652.     }
  653.  
  654.     if (self.ammo_nails < 1)
  655.     {
  656.         self.weapon = W_BestWeapon ();
  657.         W_SetCurrentAmmo ();
  658.         return;
  659.     }
  660.  
  661.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  662.     self.attack_finished = time + 0.2;
  663.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  664.     dir = aim (self, 1000);
  665.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  666.  
  667.     self.punchangle_x = -2;
  668. };
  669.  
  670.  
  671.  
  672. .float hit_z;
  673. void() spike_touch =
  674. {
  675. local float rand;
  676.     if (other == self.owner)
  677.         return;
  678.  
  679.     if (other.solid == SOLID_TRIGGER)
  680.         return; // trigger field, do nothing
  681.  
  682.     if (pointcontents(self.origin) == CONTENT_SKY)
  683.     {
  684.         remove(self);
  685.         return;
  686.     }
  687.     
  688. // hit something that bleeds
  689.     if (other.takedamage)
  690.     {
  691.         spawn_touchblood (9);
  692.         T_Damage (other, self, self.owner, 9);
  693.     }
  694.     else
  695.     {
  696.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  697.         
  698.         if (self.classname == "wizspike")
  699.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  700.         else if (self.classname == "knightspike")
  701.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  702.         else
  703.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  704.         WriteCoord (MSG_BROADCAST, self.origin_x);
  705.         WriteCoord (MSG_BROADCAST, self.origin_y);
  706.         WriteCoord (MSG_BROADCAST, self.origin_z);
  707.     }
  708.  
  709.     remove(self);
  710.  
  711. };
  712.  
  713. void() superspike_touch =
  714. {
  715. local float rand;
  716.     if (other == self.owner)
  717.         return;
  718.  
  719.     if (other.solid == SOLID_TRIGGER)
  720.         return; // trigger field, do nothing
  721.  
  722.     if (pointcontents(self.origin) == CONTENT_SKY)
  723.     {
  724.         remove(self);
  725.         return;
  726.     }
  727.     
  728. // hit something that bleeds
  729.     if (other.takedamage)
  730.     {
  731.         spawn_touchblood (18);
  732.         T_Damage (other, self, self.owner, 18);
  733.     }
  734.     else
  735.     {
  736.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  737.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  738.         WriteCoord (MSG_BROADCAST, self.origin_x);
  739.         WriteCoord (MSG_BROADCAST, self.origin_y);
  740.         WriteCoord (MSG_BROADCAST, self.origin_z);
  741.     }
  742.  
  743.     remove(self);
  744.  
  745. };
  746.  
  747.  
  748. /*
  749. ===============================================================================
  750.  
  751. PLAYER WEAPON USE
  752.  
  753. ===============================================================================
  754. */
  755.  
  756. void() W_SetCurrentAmmo =
  757. {
  758.     player_run ();      // get out of any weapon firing states
  759.  
  760.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  761.     
  762.     if (self.weapon == IT_AXE)
  763.     {
  764.         self.currentammo = 0;
  765.         self.weaponmodel = "progs/v_axe.mdl";
  766.         self.weaponframe = 0;
  767.     }
  768.     else if (self.weapon == IT_SHOTGUN)
  769.     {
  770.         self.currentammo = self.ammo_shells;
  771.         self.weaponmodel = "progs/v_shot.mdl";
  772.         self.weaponframe = 0;
  773.         self.items = self.items | IT_SHELLS;
  774.     }
  775.     else if (self.weapon == IT_SUPER_SHOTGUN)
  776.     {
  777.         self.currentammo = self.ammo_shells;
  778.         self.weaponmodel = "progs/v_shot2.mdl";
  779.         self.weaponframe = 0;
  780.         self.items = self.items | IT_SHELLS;
  781.     }
  782.     else if (self.weapon == IT_NAILGUN)
  783.     {
  784.         self.currentammo = self.ammo_nails;
  785.         self.weaponmodel = "progs/v_nail.mdl";
  786.         self.weaponframe = 0;
  787.         self.items = self.items | IT_NAILS;
  788.     }
  789.     else if (self.weapon == IT_SUPER_NAILGUN)
  790.     {
  791.         self.currentammo = self.ammo_nails;
  792.         self.weaponmodel = "progs/v_nail2.mdl";
  793.         self.weaponframe = 0;
  794.         self.items = self.items | IT_NAILS;
  795.     }
  796.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  797.     {
  798.         self.currentammo = self.ammo_rockets;
  799.         self.weaponmodel = "progs/v_rock.mdl";
  800.         self.weaponframe = 0;
  801.         self.items = self.items | IT_ROCKETS;
  802.     }
  803.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  804.     {
  805.         self.currentammo = self.ammo_rockets;
  806.         self.weaponmodel = "progs/v_rock2.mdl";
  807.         self.weaponframe = 0;
  808.         self.items = self.items | IT_ROCKETS;
  809.     }
  810.     else if (self.weapon == IT_LIGHTNING)
  811.     {
  812.         self.currentammo = self.ammo_cells;
  813.         self.weaponmodel = "progs/v_light.mdl";
  814.         self.weaponframe = 0;
  815.         self.items = self.items | IT_CELLS;
  816.     }
  817.     else
  818.     {
  819.         self.currentammo = 0;
  820.         self.weaponmodel = "";
  821.         self.weaponframe = 0;
  822.     }
  823. };
  824.  
  825. float() W_BestWeapon =
  826. {
  827.     local   float   it;
  828.     
  829.     it = self.items;
  830.  
  831.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  832.         return IT_LIGHTNING;
  833.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  834.         return IT_SUPER_NAILGUN;
  835.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  836.         return IT_SUPER_SHOTGUN;
  837.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  838.         return IT_NAILGUN;
  839.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  840.         return IT_SHOTGUN;
  841.         
  842. /*
  843.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  844.         return IT_ROCKET_LAUNCHER;
  845.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  846.         return IT_GRENADE_LAUNCHER;
  847.  
  848. */
  849.  
  850.     return IT_AXE;
  851. };
  852.  
  853. float() W_CheckNoAmmo =
  854. {
  855.     if (self.currentammo > 0)
  856.         return TRUE;
  857.  
  858.     if (self.weapon == IT_AXE)
  859.         return TRUE;
  860.     
  861.     self.weapon = W_BestWeapon ();
  862.  
  863.     W_SetCurrentAmmo ();
  864.     
  865. // drop the weapon down
  866.     return FALSE;
  867. };
  868.  
  869. /*
  870. ============
  871. W_Attack
  872.  
  873. An attack impulse can be triggered now
  874. ============
  875. */
  876. void()  player_axe1;
  877. void()  player_axeb1;
  878. void()  player_axec1;
  879. void()  player_axed1;
  880. void()  player_shot1;
  881. void()  player_nail1;
  882. void()  player_light1;
  883. void()  player_rocket1;
  884.  
  885. void() W_Attack =
  886. {
  887.     local   float   r;
  888.  
  889.     if (!W_CheckNoAmmo ())
  890.         return;
  891.  
  892.     makevectors (self.v_angle);         // calculate forward angle for velocity
  893.     self.show_hostile = time + 1;   // wake monsters up
  894.  
  895.     if (self.weapon == IT_AXE)
  896.     {
  897.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  898.         r = random();
  899.         if (r < 0.25)
  900.             player_axe1 ();
  901.         else if (r<0.5)
  902.             player_axeb1 ();
  903.         else if (r<0.75)
  904.             player_axec1 ();
  905.         else
  906.             player_axed1 ();
  907.         self.attack_finished = time + 0.5;
  908.     }
  909.     else if (self.weapon == IT_SHOTGUN)
  910.     {
  911.         player_shot1 ();
  912.         W_FireShotgun ();
  913.         self.attack_finished = time + 0.5;
  914.     }
  915.     else if (self.weapon == IT_SUPER_SHOTGUN)
  916.     {
  917.         player_shot1 ();
  918.         W_FireSuperShotgun ();
  919.         self.attack_finished = time + 0.7;
  920.     }
  921.     else if (self.weapon == IT_NAILGUN)
  922.     {
  923.         player_nail1 ();
  924.     }
  925.     else if (self.weapon == IT_SUPER_NAILGUN)
  926.     {
  927.         player_nail1 ();
  928.     }
  929.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  930.     {
  931.         player_rocket1();
  932.         W_FireGrenade();
  933.         self.attack_finished = time + 0.6;
  934.     }
  935.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  936.     {
  937.         player_rocket1();
  938.         W_FireRocket();
  939.         self.attack_finished = time + 0.8;
  940.     }
  941.     else if (self.weapon == IT_LIGHTNING)
  942.     {
  943.         player_light1();
  944.         self.attack_finished = time + 0.1;
  945.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  946.     }
  947. };
  948.  
  949. /*
  950. ============
  951. W_ChangeWeapon
  952.  
  953. ============
  954. */
  955. void() W_ChangeWeapon =
  956. {
  957.     local   float   it, am, fl;
  958.     
  959.     it = self.items;
  960.     am = 0;
  961.     
  962.     if (self.impulse == 1)
  963.     {
  964.         fl = IT_AXE;
  965.     }
  966.     else if (self.impulse == 2)
  967.     {
  968.         fl = IT_SHOTGUN;
  969.         if (self.ammo_shells < 1)
  970.             am = 1;
  971.     }
  972.     else if (self.impulse == 3)
  973.     {
  974.         fl = IT_SUPER_SHOTGUN;
  975.         if (self.ammo_shells < 2)
  976.             am = 1;
  977.     }       
  978.     else if (self.impulse == 4)
  979.     {
  980.         fl = IT_NAILGUN;
  981.         if (self.ammo_nails < 1)
  982.             am = 1;
  983.     }
  984.     else if (self.impulse == 5)
  985.     {
  986.         fl = IT_SUPER_NAILGUN;
  987.         if (self.ammo_nails < 2)
  988.             am = 1;
  989.     }
  990.     else if (self.impulse == 6)
  991.     {
  992.         fl = IT_GRENADE_LAUNCHER;
  993.         if (self.ammo_rockets < 1)
  994.             am = 1;
  995.     }
  996.     else if (self.impulse == 7)
  997.     {
  998.         fl = IT_ROCKET_LAUNCHER;
  999.         if (self.ammo_rockets < 1)
  1000.             am = 1;
  1001.     }
  1002.     else if (self.impulse == 8)
  1003.     {
  1004.         fl = IT_LIGHTNING;
  1005.         if (self.ammo_cells < 1)
  1006.             am = 1;
  1007.     }
  1008.  
  1009.     self.impulse = 0;
  1010.     
  1011.     if (!(self.items & fl))
  1012.     {   // don't have the weapon or the ammo
  1013.         sprint (self, "no weapon.\n");
  1014.         return;
  1015.     }
  1016.     
  1017.     if (am)
  1018.     {   // don't have the ammo
  1019.         sprint (self, "not enough ammo.\n");
  1020.         return;
  1021.     }
  1022.  
  1023. //
  1024. // set weapon, set ammo
  1025. //
  1026.     self.weapon = fl;       
  1027.     W_SetCurrentAmmo ();
  1028. };
  1029.  
  1030. /*
  1031. ============
  1032. CheatCommand
  1033. ============
  1034. */
  1035. void() CheatCommand =
  1036. {
  1037.     if (deathmatch || coop)
  1038.         return;
  1039.  
  1040.     self.ammo_rockets = 100;
  1041.     self.ammo_nails = 200;
  1042.     self.ammo_shells = 100;
  1043.     self.items = self.items | 
  1044.         IT_AXE |
  1045.         IT_SHOTGUN |
  1046.         IT_SUPER_SHOTGUN |
  1047.         IT_NAILGUN |
  1048.         IT_SUPER_NAILGUN |
  1049.         IT_GRENADE_LAUNCHER |
  1050.         IT_ROCKET_LAUNCHER |
  1051.         IT_KEY1 | IT_KEY2;
  1052.  
  1053.     self.ammo_cells = 200;
  1054.     self.items = self.items | IT_LIGHTNING;
  1055.  
  1056.     self.weapon = IT_ROCKET_LAUNCHER;
  1057.     self.impulse = 0;
  1058.     W_SetCurrentAmmo ();
  1059. };
  1060.  
  1061. /*
  1062. ============
  1063. CycleWeaponCommand
  1064.  
  1065. Go to the next weapon with ammo
  1066. ============
  1067. */
  1068. void() CycleWeaponCommand =
  1069. {
  1070.     local   float   it, am;
  1071.     
  1072.     it = self.items;
  1073.     self.impulse = 0;
  1074.     
  1075.     while (1)
  1076.     {
  1077.         am = 0;
  1078.  
  1079.         if (self.weapon == IT_LIGHTNING)
  1080.         {
  1081.             self.weapon = IT_AXE;
  1082.         }
  1083.         else if (self.weapon == IT_AXE)
  1084.         {
  1085.             self.weapon = IT_SHOTGUN;
  1086.             if (self.ammo_shells < 1)
  1087.                 am = 1;
  1088.         }
  1089.         else if (self.weapon == IT_SHOTGUN)
  1090.         {
  1091.             self.weapon = IT_SUPER_SHOTGUN;
  1092.             if (self.ammo_shells < 2)
  1093.                 am = 1;
  1094.         }       
  1095.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1096.         {
  1097.             self.weapon = IT_NAILGUN;
  1098.             if (self.ammo_nails < 1)
  1099.                 am = 1;
  1100.         }
  1101.         else if (self.weapon == IT_NAILGUN)
  1102.         {
  1103.             self.weapon = IT_SUPER_NAILGUN;
  1104.             if (self.ammo_nails < 2)
  1105.                 am = 1;
  1106.         }
  1107.         else if (self.weapon == IT_SUPER_NAILGUN)
  1108.         {
  1109.             self.weapon = IT_GRENADE_LAUNCHER;
  1110.             if (self.ammo_rockets < 1)
  1111.                 am = 1;
  1112.         }
  1113.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1114.         {
  1115.             self.weapon = IT_ROCKET_LAUNCHER;
  1116.             if (self.ammo_rockets < 1)
  1117.                 am = 1;
  1118.         }
  1119.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1120.         {
  1121.             self.weapon = IT_LIGHTNING;
  1122.             if (self.ammo_cells < 1)
  1123.                 am = 1;
  1124.         }
  1125.     
  1126.         if ( (self.items & self.weapon) && am == 0)
  1127.         {
  1128.             W_SetCurrentAmmo ();
  1129.             return;
  1130.         }
  1131.     }
  1132.  
  1133. };
  1134.  
  1135. /*
  1136. ============
  1137. ServerflagsCommand
  1138.  
  1139. Just for development
  1140. ============
  1141. */
  1142. void() ServerflagsCommand =
  1143. {
  1144.     serverflags = serverflags * 2 + 1;
  1145. };
  1146.  
  1147. void() QuadCheat =
  1148. {
  1149.     if (deathmatch || coop)
  1150.         return;
  1151.     self.super_time = 1;
  1152.     self.super_damage_finished = time + 30;
  1153.     self.items = self.items | IT_QUAD;
  1154.     dprint ("quad cheat\n");
  1155. };
  1156.  
  1157. /*
  1158. ============
  1159. ImpulseCommands
  1160.  
  1161. ============
  1162. */
  1163. void() ImpulseCommands =
  1164. {
  1165.     if (self.impulse >= 1 && self.impulse <= 8)
  1166.         W_ChangeWeapon ();
  1167.  
  1168.     if (self.impulse == 9)
  1169.         CheatCommand ();
  1170.     if (self.impulse == 10)
  1171.         CycleWeaponCommand ();
  1172.     if (self.impulse == 11)
  1173.         ServerflagsCommand ();
  1174.     if (self.impulse == 15)
  1175.         W_FireMotion();
  1176.     if (self.impulse == 16)
  1177.         GiveMotionNails();
  1178.  
  1179.     if (self.impulse == 255)
  1180.         QuadCheat ();
  1181.         
  1182.     self.impulse = 0;
  1183. };
  1184.  
  1185. /*
  1186. ============
  1187. W_WeaponFrame
  1188.  
  1189. Called every frame so impulse events can be handled as well as possible
  1190. ============
  1191. */
  1192. void() W_WeaponFrame =
  1193. {
  1194.     if (time < self.attack_finished)
  1195.         return;
  1196.  
  1197.     ImpulseCommands ();
  1198.     
  1199. // check for attack
  1200.     if (self.button0)
  1201.     {
  1202.         SuperDamageSound ();
  1203.         W_Attack ();
  1204.     }
  1205. };
  1206.  
  1207. /*
  1208. ========
  1209. SuperDamageSound
  1210.  
  1211. Plays sound if needed
  1212. ========
  1213. */
  1214. void() SuperDamageSound =
  1215. {
  1216.     if (self.super_damage_finished > time)
  1217.     {
  1218.         if (self.super_sound < time)
  1219.         {
  1220.             self.super_sound = time + 1;
  1221.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1222.         }
  1223.     }
  1224.     return;
  1225. };
  1226.  
  1227.  
  1228.